﻿using System;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Generic;
using System.Text;
using Texfina.Core.Common;
using Texfina.Common.Mg;
using Texfina.Core.Web;
using Texfina.Core.Data;
using Texfina.Entity.Rh;
using Texfina.Entity.Mg;
using Texfina.Entity.Sy;
using RHBOQry = Texfina.BOQry.Rh;
using MGBOQry = Texfina.BOQry.Mg;
using RHBOMnt = Texfina.BOMnt.Rh;
using SYBOQry = Texfina.BOQry.Sy;

namespace RH
{
   public partial class wfPrograVacaMnt : EditPage 
   {
      public string strYear
      {
         get { return (string)this.ViewState["_strYear"]; }
         set { this.ViewState["_strYear"] = value; }
      }

      public DateTime dtmFechaIngPla
      {
         get { return (DateTime)this.ViewState["_dtmFeIngre"]; }
         set { this.ViewState["_dtmFeIngre"] = value; }
      }

      public const int _GRDLIST_STANULADO = 5;

      protected void Page_Load(object sender, EventArgs e)
      {
           if (this.IsPostBack){
               this.LoadInPostBack();
               return;}
           this.LoadData();
      }

      public override void LoadInPostBack()
      {
         this.RegisterGeneralScripts();
      }

      public override void LoadInitialSettings()
      {
         this.FormEditAction = (FormEditAction) Enum.Parse(typeof(FormEditAction), Request.QueryString["formEA"]);
         this.SetInitialTitle("Programación de Vacaciones");
      }

      public override void LoadListControls()
      {
         strYear = DateTime.Now.Year.ToString();
         lblYear.Text = strYear; 

         ETablaGenDet objEDet = new ETablaGenDet();

         MGBOQry.ITablaGen objBOI = (MGBOQry.ITablaGen)WCFHelper.GetObject<MGBOQry.ITablaGen>(typeof(MGBOQry.TablaGen));

         objEDet.IdTabla = ConstMultitabla.TIPO_DOCUMENTO;
         DataTable dt = objBOI.GetDetailByList(objEDet);
         WebHelper.LoadListControl(ddlidTDocIden, dt, "dsAbrev", "idCodigo", true, true);

      }

      public override void DataToControls()
      {
         EPersonal objE = new EPersonal();
         IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.Personal));
         objE.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString() ;
         objE.IdPersonal = Request.QueryString["IdPersonal"];
         objE = (EPersonal)objBO.GetByKey(objE);

         if (objE != null)
         {

            WebHelper.EntityToControl(objE, "IdPersonal", txtidPersonal);
            WebHelper.EntityToControl(objE,"FeNacimien",txtfeNacimiento);
            WebHelper.EntityToControl(objE, "IdSexo", ddlidSexo);

            ECliProv objECli = new ECliProv();
            IBOQuery objBOCli = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(MGBOQry.CliProv));
            objECli.IdCliProv = objE.IdCliProv;
            objECli = (ECliProv)objBOCli.GetByKey(objECli);

            if (objECli != null)
            {
               WebHelper.EntityToControl(objECli,"IdCliProv",hdnidCliProv);
               WebHelper.EntityToControl(objECli,"DsAPaterno",txtdsAPaterno);
               WebHelper.EntityToControl(objECli,"DsAMaterno",txtdsAMaterno);
               WebHelper.EntityToControl(objECli,"DsNombres",txtdsNombres);
               WebHelper.EntityToControl(objECli,"IdTDocIden",ddlidTDocIden);
               WebHelper.EntityToControl(objECli, "NuDocIden", txtnuDocIden);
               
            }
              
         }

         dtmFechaIngPla = DateTime.Parse(objE.FeIngpla.ToString());
         this.txtfeIngrePla.Text = dtmFechaIngPla.ToString("dd/MM/yyyy");
         this.txtfeCumpleAnio.Text = dtmFechaIngPla.AddYears(1).AddDays(-1).ToString("dd/MM/yyyy");     
         
         this.GetVacaProg(strYear);

      }

      public void GetVacaProg(string year)
      {
         EPerVacaProg objEDet = new EPerVacaProg();
         IBOQuery objBODet = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.PerVacaProg));
         objEDet.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
         objEDet.IdPersonal = Request.QueryString["IdPersonal"];
         objEDet.IdPeriVac = year;

         DataTable dt = objBODet.GetByParentKey(objEDet);

         this.GridSetDataBinding(grdList, dt);
      
         this.txtfeInicioPp.DateMin = new DateTime(int.Parse(strYear) + 1, dtmFechaIngPla.Month, dtmFechaIngPla.Day);
         this.txtfeInicioPp.DateMax = new DateTime(int.Parse(strYear) + 2, dtmFechaIngPla.Month, dtmFechaIngPla.Day).AddDays(-1);

         this.txtfeFinPp.DateMin = this.txtfeInicioPp.DateMin;
         this.txtfeFinPp.DateMax = this.txtfeInicioPp.DateMax;
         
      }

      public override void RegisterGeneralScripts()
      { 
         txtidPersonal.Attributes.Add("readonly", "true");
         this.txtfeInicioPp.Attributes.Add("readonly", "true");
         this.txtfeFinPp.Attributes.Add("readonly", "true");

         StringBuilder sb = new StringBuilder();

         //sb.AppendLine("var varRet = modalDialog('../MG/wfUbigeoBnd.aspx',725,400);");
         //sb.AppendLine("if(varRet==null)");
         //sb.AppendLine("return false;");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidPais.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[0];");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidDepa.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[2];");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidProv.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[4];");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidDist.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[6];");
         //sb.AppendLine("ctl = document.getElementById('" + this.txtdsUbigeo.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[1] + ' / ' + varRet[3] + ' / ' + varRet[5] + ' / ' + varRet[7];");
         //sb.AppendLine("ctl.title = ctl.value;");
         //this.txtdsUbigeo.OnClientClick = sb.ToString();

         //sb = new StringBuilder();

         //sb.AppendLine("var varRet = modalDialog('../MG/wfUbigeoBnd.aspx',725,400);");
         //sb.AppendLine("if(varRet==null)");
         //sb.AppendLine("return false;");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidPais2.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[0];");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidDepa2.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[2];");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidProv2.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[4];");
         //sb.AppendLine("ctl = document.getElementById('" + this.hdnidDist2.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[6];");
         //sb.AppendLine("ctl = document.getElementById('" + this.txtdsUbigeo2.ClientID + "');");
         //sb.AppendLine("ctl.value = varRet[1] + ' / ' + varRet[3] + ' / ' + varRet[5] + ' / ' + varRet[7];");
         //sb.AppendLine("ctl.title = ctl.value;");
         //this.txtdsUbigeo2.OnClientClick = sb.ToString();

         sb = new StringBuilder();


         sb.AppendLine("function validateEditForm(key){");
  
         sb.AppendLine("menu_doPostBack('"+mnuToolbar.ClientID+"','"+mnuToolbar.UniqueID+"',key);");
         sb.AppendLine("}");


         sb.AppendLine("function OnChangeRangeDates(){");
         sb.AppendLine("dIni = document.getElementById('" + this.txtfeInicioPp.ClientID + "').value;");
         sb.AppendLine("dFin = document.getElementById('" + this.txtfeFinPp.ClientID + "').value;");
         sb.AppendLine("   if(dIni!='' && dFin!=''){");
         sb.AppendLine("      var numDias = DateDiff('d',$('#" + this.txtfeInicioPp.ClientID + "').datepicker('getDate'),$('#" + this.txtfeFinPp.ClientID + "').datepicker('getDate'));");
         sb.AppendLine("      document.getElementById('" + this.txtnuDiasPp.ClientID + "').value= numDias;");
         sb.AppendLine("   }");
         sb.AppendLine("}");

         ScriptManager.RegisterStartupScript(this, this.GetType(), "ScriptRegister", sb.ToString(), true);

         this.txtfeInicioPp.OnClientClickDay = "OnChangeRangeDates();";
         this.txtfeFinPp.OnClientClickDay = "OnChangeRangeDates();";
      }

      public void RegisterEditPopupScripts()
      {
         StringBuilder sb = new StringBuilder();

         sb.AppendLine("function validate" + this.bttOkPopup.ID + "(){");

         sb.AppendLine("return true;}");

         ScriptManager.RegisterStartupScript(this, this.GetType(), "validatePopup", sb.ToString(), true);

         this.bttOkPopup.OnClientClick ="return validate" + bttOkPopup.ID + "();";
         this.bttCancelPopup.OnClientClick =  "$find('" + this.mdlPopup.ClientID + "').hide();return false;";
      
      }

      protected void mnuToolbar_MenuItemClick(Object sender, MenuEventArgs e)
      {
         if(e.Item == null)
            return;

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_SAVE:
            case ConstMenuToolbarValue.BUTTON_SAVENEW:
               if(this.FormEditAction != FormEditAction.Delete)
                  this.SaveData(e.Item.Value);
               else
                  this.DeleteData();
               break; 

            case ConstMenuToolbarValue.BUTTON_EXIT:
               this.Response.Redirect("wfPrograVacaBnd.aspx?Filter=1");
               break;
      
         }
        
      }

      protected void mnuGrid_MenuItemClick(Object sender, MenuEventArgs e)
      {
         if(e.Item == null)
            return;

         switch (e.Item.Value)
         {
            case ConstMenuToolbarValue.BUTTON_NEW:
                 this.GridEditAction = GridEditAction.AddNew;
                 this.lblTitlePopup.Text = "Derechohabientes (Nuevo)";
                 this.mdlPopup.Show();
                 this.LoadDataEditPopup(grdList, -1);
                 this.RegisterEditPopupScripts();
                 break;
         }
        
      }

      protected void grdList_PreRender(object sender, EventArgs e)
      {

         GridViewRow gv = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
         TableCell tbCell = new TableCell();
         tbCell.ColumnSpan = 4;
         tbCell.Text = "";
         tbCell.Attributes.Add("style", "text-align:center;heigth:10px;");
         gv.Cells.Add(tbCell);

         tbCell = new TableCell();
         tbCell.ColumnSpan = 3;
         tbCell.Text = "Inicial";
         tbCell.Attributes.Add("style", "text-align:center;border-right :solid 1px #C9C9C9;border-left :solid 1px #C9C9C9;");
         gv.Cells.Add(tbCell);
         tbCell = new TableCell();
         tbCell.ColumnSpan = 3;
         tbCell.Text = "Final";
         tbCell.Attributes.Add("style", "text-align:center;border-right :solid 1px #C9C9C9;");
         gv.Cells.Add(tbCell);
         tbCell = new TableCell();
         tbCell.ColumnSpan = 6;
         tbCell.Text = "";
         tbCell.Attributes.Add("style", "text-align:center;heigth:10px;");
         gv.Cells.Add(tbCell);
         grdList.Controls[0].Controls.AddAt(0, gv);
         grdList.HeaderStyle.CssClass = "esdMultiHeaderStyle";

      }

      protected void grdList_RowCommand(Object sender, GridViewCommandEventArgs e)
      {
         this.EditRowIndex = Convert.ToInt32(e.CommandArgument);

         switch (e.CommandName)
         {
            case ConstGridRowCommand.GRIDEDIT:
               this.lblTitlePopup.Text = "Derechohabientes (Editar)";
               this.GridEditAction = GridEditAction.Edit;
               this.mdlPopup.Show();
               this.LoadDataEditPopup(grdList, this.EditRowIndex);
               this.RegisterEditPopupScripts();
               break;
            case ConstGridRowCommand.GRIDDELETE:
               this.lblTitlePopup.Text = "Derechohabientes (Dar de Baja)";
               this.GridEditAction = GridEditAction.Delete;
               this.mdlPopup.Show();
               this.LoadDataEditPopup(grdList, this.EditRowIndex);
               this.RegisterEditPopupScripts();
               break;
         }
      }

      protected void grdList_RowDataBound(Object sender, GridViewRowEventArgs e)
      {
         if (e.Row.RowType == DataControlRowType.DataRow)
         {
             if (e.Row.Cells[_GRDLIST_STANULADO].Text == ConstFlagEstado.ACTIVADO)
            { e.Row.ForeColor = System.Drawing.Color.Red; }
         }


      }

      protected void bttOkPopup_Click(object sender, EventArgs e)
      {
         
         Object objResNuSec = null;
         int intResNusec = 0;
         DataTable dt= (DataTable)this.DataSource;
         DataRow dr= null;
         DataRow drVa = null;

         if(this.GridEditAction == GridEditAction.AddNew || this.GridEditAction == GridEditAction.Copy )
         {
            EPersonal objE = new EPersonal();
            IBOQuery objBO = (IBOQuery)WCFHelper.GetObject<IBOQuery>(typeof(RHBOQry.Personal));
            objE.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
            objE.IdPersonal = Request.QueryString["IdPersonal"];
            objE = (EPersonal)objBO.GetByKey(objE);




            EPerVacaProg objEDet = new EPerVacaProg();
            RHBOQry.IPerVacaProg objBODet = (RHBOQry.IPerVacaProg)WCFHelper.GetObject<RHBOQry.IPerVacaProg>(typeof(RHBOQry.PerVacaProg));
            objEDet.IdPersonal = this.txtidPersonal.Text;
            objEDet.IdEmpresa = Session[ConstSessionVar.EMPRESA].ToString();
            objEDet.IdForPago = ConstFormaPago.OFICIAL;
            objEDet.IdPlanilla = "002";
            objEDet.FeVacaIni = DateTime.Parse(this.txtfeInicioPp.Text).Date;
            objEDet.FeVacaFin = DateTime.Parse(this.txtfeFinPp.Text).Date;
            DataTable dtVa = objBODet.GetProcesosXRangoFecha(objEDet);
          
            if (dtVa.Rows.Count > 0)
               drVa = dtVa.Rows[0];
            else
               return;
                        
            objResNuSec = dt.Compute("MAX(nuSecuen)", "");
            if (objResNuSec == null || objResNuSec.ToString() == "")
               intResNusec = 0;
            else
               intResNusec = Convert.ToInt32(objResNuSec);
            intResNusec += 1;
            dr = dt.NewRow();
            dr["nuSecuen"] = intResNusec;
         }
         else
         {
            dr = this.GridGetRowFromDataKey(grdList, this.EditRowIndex);
         }

         if (this.GridEditAction != GridEditAction.Delete)
         {
            dr["idEmpresa"] = drVa["idEmpresa"];
            dr["idPersonal"] = drVa["idPersonal"];
            dr["idPeriVac"] = strYear;
            dr["idForPago"] = drVa["idForPago"];

            dr["idPlanilla"] = drVa["idPlanilla"];
            dr["dsPlanilla"] = "Vacaciones Obrero";

            dr["idConRemu"] = "107";
            dr["dsConRemu"] = "VACACIONES";

            dr["nuDiasVaca"] = this.txtnuDiasPp.Text;

            dr["mtVaca"] = 0.0;

            dr["idPeriAnualIni"] = drVa["idPeriAnualIni"];
            dr["nuProcAnualIni"] = drVa["nuProcAnualIni"];
            dr["feVacaIni"] = drVa["feVacaIni"];
            dr["idPeriAnualFin"] = drVa["idPeriAnualFin"];
            dr["nuProcAnualFin"] = drVa["nuProcAnualFin"];
            dr["feVacaFin"] = drVa["feVacaFin"];
            dr["nuDiasGozado"] = drVa["nuDiasGozado"];
            dr["stVaca"] = drVa["stVaca"];
            dr["stAnulado"] = ConstFlagEstado.DESACTIVADO;
         } 
         else
         {
            dr["stAnulado"] = ConstFlagEstado.ACTIVADO;
         }

         if(this.GridEditAction == GridEditAction.AddNew || this.GridEditAction == GridEditAction.Copy)
         {
            dt.Rows.Add(dr);
         }
         
         this.GridSetDataBinding(grdList, dt);
      }

      protected void bttBackYear_Click(object sender, EventArgs e)
      {
         strYear = (int.Parse(lblYear.Text==""?"0":lblYear.Text) - 1).ToString() ;
         lblYear.Text = strYear;
         this.GetVacaProg(strYear);
      }

      protected void bttNextYear_Click(object sender, EventArgs e)
      {
         strYear = (int.Parse(lblYear.Text == "" ? "0" : lblYear.Text) + 1).ToString();
         lblYear.Text = strYear;
         this.GetVacaProg(strYear);
      }

      public override void LoadDataEditPopup(GridView grid, int rowIndex)
      {
          this.ClearEditPopup();
          this.LockControlsPopup();

          DataRow dr= this.GridGetRowFromDataKey(this.DataSource, grdList, rowIndex);

          if (dr == null)
              return;

          //WebHelper.RowToControl(dr, "dsAPaterno", txtdsApePaternoDH);
          //WebHelper.RowToControl(dr,"dsAMaterno",txtdsApeMaternoDH);
          //WebHelper.RowToControl(dr,"dsNombres",txtdsNombresDH);
          //WebHelper.RowToControl(dr,"idTDocIden",ddlidTipoDocDH);
          //WebHelper.RowToControl(dr,"nuDocIden",txtnuDocDH);
          //WebHelper.RowToControl(dr,"feNacimien",txtfeNacimientoDH);
          //WebHelper.RowToControl(dr,"idSexo",ddlidGeneroDH);
          //WebHelper.RowToControl(dr,"idVincFam",ddlidVincFamDH);
          //WebHelper.RowToControl(dr,"dsVincFam",ddlidVincFamDH);
          //WebHelper.RowToControl(dr,"idTipoDocAcre",ddlidTipoDocVincFamDH);
          //WebHelper.RowToControl(dr,"nuDocAcre",txtnuDocVincFamDH);
          //WebHelper.RowToControl(dr,"nuMesConcep",txtfeConcepDH);
          //WebHelper.RowToControl(dr,"nuTlfCodLDN",txtnuCodLDN);
          //WebHelper.RowToControl(dr,"nuTelf",txtnuTelefonoDH);
          //WebHelper.RowToControl(dr,"dsEmail",txtdsEmailDH);
          //WebHelper.RowToControl(dr,"feBaja",txtfeBajaDH);           
          //WebHelper.RowToControl(dr,"idMotivBaja",ddlidMotivoBajaDH);
          //WebHelper.RowToControl(dr,"dsUbigeo",txtdsUbigeo);
          //WebHelper.RowToControl(dr,"idPais1",hdnidPais);
          //WebHelper.RowToControl(dr,"idDepa1",hdnidDepa);
          //WebHelper.RowToControl(dr,"idProv1",hdnidProv);
          //WebHelper.RowToControl(dr,"idDist1",hdnidDist);
          //WebHelper.RowToControl(dr,"idTipoVia1",ddlidTipoVia);
          //WebHelper.RowToControl(dr,"dsNombreVia1",txtdsNombreVia);
          //WebHelper.RowToControl(dr,"nuVia1",txtnuVia);
          //WebHelper.RowToControl(dr,"nuDepa1",txtnuDpto);
          //WebHelper.RowToControl(dr,"nuInterior1",txtnuInterior);
          //WebHelper.RowToControl(dr,"nuMz1",txtdsManzana);
          //WebHelper.RowToControl(dr,"nuLote1",txtdsLote);
          //WebHelper.RowToControl(dr,"nuKm1",txtdsKilometro);
          //WebHelper.RowToControl(dr,"nuBlock1",txtdsBlock);
          //WebHelper.RowToControl(dr,"dsEtapa1",txtdsEtapa);
          //WebHelper.RowToControl(dr,"idTipoZona1",ddlidTipoZona);
          //WebHelper.RowToControl(dr,"dsNombZona1",txtdsNombZona);
          //WebHelper.RowToControl(dr,"dsReferen1",txtdsReferen);
          //WebHelper.RowToControl(dr,"dsUbigeo2",txtdsUbigeo2);
          //WebHelper.RowToControl(dr,"idPais2",hdnidPais2);
          //WebHelper.RowToControl(dr,"idDepa2",hdnidDepa2);
          //WebHelper.RowToControl(dr,"idProv2",hdnidProv2);
          //WebHelper.RowToControl(dr,"idDist2",hdnidDist2);
          //WebHelper.RowToControl(dr,"idTipoVia2",ddlidTipoVia2);
          //WebHelper.RowToControl(dr,"dsNombreVia2",txtdsNombreVia2);
          //WebHelper.RowToControl(dr,"nuVia2",txtnuVia2);
          //WebHelper.RowToControl(dr,"nuDepa2",txtnuDpto2);
          //WebHelper.RowToControl(dr,"nuInterior2",txtnuInterior2);
          //WebHelper.RowToControl(dr,"nuMz2",txtdsManzana2);
          //WebHelper.RowToControl(dr,"nuLote2",txtdsLote2);
          //WebHelper.RowToControl(dr,"nuKm2",txtdsKilometro2);
          //WebHelper.RowToControl(dr,"nuBlock2",txtdsBlock2);
          //WebHelper.RowToControl(dr,"dsEtapa2",txtdsEtapa2);
          //WebHelper.RowToControl(dr,"idTipoZona2",ddlidTipoZona2);
          //WebHelper.RowToControl(dr,"dsNombZona2",txtdsNombZona2);
          //WebHelper.RowToControl(dr,"dsReferen2",txtdsReferen2);

          //if (ConstDirecReferEsSalud.DIRECCION_UNO == dr["stAsisEsSalud"].ToString())
          //   this.rbDireccion1.Checked = true;
          //else
          //   this.rbDireccion2.Checked = true;
      }
      
      public new void ClearEditPopup()
      {
         txtfeInicioPp.Text = "";
         txtfeFinPp.Text = "";
         txtnuDiasPp.Text = "";
      }

      public void LockControlsPopup()
      {
      
      }

      public override void SaveData(String key)
      {
           if (this.ValidateData() == false )
            return;

            IEntityBase objE= (IEntityBase) this.CreateEntitySet();
            IBOUpdate objPro = (IBOUpdate)WCFHelper.GetObject<IBOUpdate>(typeof(RHBOMnt.Personal));

            String[] strRet = objPro.UpdateData(objE);
            String strMsg = "";

            switch (this.FormEditAction)
            { 
            
               case FormEditAction.AddNew:
               case FormEditAction.Copy:
                     strMsg = "Se ha registrado los derechohabientes : " + strRet[0].ToString() ;
                     break;
               default:
                     strMsg = "Se ha modificado los derechohabientes : " + txtidPersonal.Text;
                     break;
            }
            this.hdnMsgOPB.Value = this.CreatePostbackMessage("CORRECTO", strMsg, TypeMessageAlert.correct, false, "wfPerDereHabiBnd.aspx?Filter=1");
      }

      public override void DeleteData()
      {
            IEntityBase objE= (IEntityBase)this.CreateEntitySet();
            IBOUpdate objPro = (IBOUpdate)WCFHelper.GetObject<IBOUpdate>(typeof(RHBOMnt.Personal));
            objPro.DeleteData(objE);

            this.hdnMsgOPB.Value = this.CreatePostbackMessage("CORRECTO", "Se anulo el derechohabiente  : " + txtidPersonal.Text, TypeMessageAlert.correct, false, "wfPerDereHabiBnd.aspx?Filter=1");
       
      }

      public override Object CreateEntitySet()
      {

            DataTable dt= (DataTable)this.DataSource;
            this.ClearDeletedRow(this.DataSource, "stAnulado");
            IList<EPerDepen> colECerti = new List<EPerDepen>();

            if( this.FormEditAction == FormEditAction.Delete )
            {
                  foreach(DataRow dr in dt.Rows)
                  {
                     this.MarkDeletedRow(dr, "stAnulado");
                  }
            }
       

            for (int intTypeUpd = 0; intTypeUpd<=1; intTypeUpd++)
            {
               DataTable dtChange= null;
               if( intTypeUpd == 0 )
                  dtChange = dt.GetChanges(DataRowState.Added);
               else
                  dtChange = dt.GetChanges(DataRowState.Modified);
         

               if (dtChange != null )
               {
                  foreach(DataRow drDet in dtChange.Rows)
                  {
                     EPerDepen objEDet= DataHelper.CopyDataRowToEntity<EPerDepen>(drDet,typeof(EPerDepen));

                     if(drDet.RowState == DataRowState.Added)
                        objEDet.EntityState = EntityState.Added;
               
                     if(drDet.RowState == DataRowState.Modified)
                     {
                        if(objEDet.StAnulado == ConstFlagEstado.DESACTIVADO)
                           objEDet.EntityState = EntityState.Modified;
                        else
                           objEDet.EntityState = EntityState.Deleted;
                     }

                     colECerti.Add(objEDet);
                  }
               }
            }
         
            EPersonalSet objESet = new EPersonalSet();
            objESet.ColPerDepen = colECerti; 

          return objESet;
      }
    
      public override void LockControls()
      {
         //if (this.FormEditAction == FormEditAction.Delete)
         //else  
      }

   }
}